#include<iostream>
#include<vector>
#include<string>
using namespace std;

vector<int> findAnagrams(string s, string p)
{
    vector<int> res;
    string reslut;
    for (int left = 0, right = 0; right < s.size(); right++)
    {
        if (reslut.find(s[right]) != string::npos)
        {
            int pos = reslut.find(s[right]);
            reslut.erase(pos, 1);
            left++;
        }
        reslut += s[right];

        if (p.find(s[right]) == string::npos)
        {
            reslut = "";
            left = right + 1;
        }
        if (reslut.size() == p.size())
            res.push_back(left);
    }
    return res;
}
int main()
{
    string s = "cbaebabacd", p = "abc";
    findAnagrams(s,p);
}